package com.kmt.plaza.config;

import com.kmt.plaza.interceptor.CheckTokenInterceptor;
import com.kmt.plaza.interceptor.ContinuationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//声明当前类为配置类，用于取代bean.xml配置文件注册bean对象
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private CheckTokenInterceptor checkTokenInterceptor;
    @Autowired
    private ContinuationInterceptor continuationInterceptor;
    @Override
    //添加拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkTokenInterceptor)
                .addPathPatterns("/shopCart/**")//拦截购物车请求
                .addPathPatterns("/orders/**")//拦截订单请求
                .excludePathPatterns("/useraddress/**")
                .excludePathPatterns("/user/check/**");
        registry.addInterceptor(continuationInterceptor).addPathPatterns("/**").excludePathPatterns("user/login/**").excludePathPatterns("user/login/**").excludePathPatterns("user/upload/**");
    }
}
